package com.amat0urheu.dao;

import com.amat0urheu.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from mc_user where uname=#{uname} and upassword=#{upassword}")
    User selectByUserNameAndPassword(String uname, String upassword);

    @Select("select * from mc_user where uname=#{uname}")
    User selectLoginByUserName(String uname);


    @Select("select * from mc_user where uname=#{uname}")
    User selectByUserName(String uname);

    @Select("select uid from mc_user where uname=#{uname}")
    int selectIdByUserName(String uname);

    @Select("select * from mc_user where uid=#{uid}")
    User selectUserByIdForAdmin(Integer uid);

    @Select("select uid, uname, sex, skill, email, unit, sign, role, score, teamName from mc_user where uid=#{uid}")
    User selectUserByIdForUser(Integer uid);

    @Select("select * from mc_user")
    List<User> selectAllUser();

    @Select("select * from mc_user where ${key} like #{value}")
    List<User> selectSearchUser(String key, String value);


  @Select("update mc_user set score=${score} where uid=${uid}")
    void updateScoreByuid(int uid,int score);
@Update("update mc_user set teamName=#{tname} where uname=#{username}")
    void updatePeoTeam(String tname, String username);
    @Select("select count(*) from mc_user where uname=#{username} and teamName is not null")
    int haveTeam(String username);

    @Select("select count(*) from mc_super_user where username=#{name}")
    int finSuperUserByUsename(String name);
    @Select("select teamName from mc_user where uname=#{name}")
    String getTeanNameByName(String name);
    @Select("select upassword from mc_user where uname=#{uname}")
    String getPasswordByuserName(String user);
    @Update("update mc_user set upassword=#{tname} where uname=#{user}")
    int updatePasswordByuserName(String user, String md5NewPassword);
    @Select("select  uname from mc_user where teamName =#{teamName}")
    List<String> getTeamPeoples(String  teamName);
    @Select("select count(*) from mc_user where tname=#{teamName}")
    int getNumOfTeam(String teamName);
}
